import * as types from "../types";
import * as api from "../../http/admin-api";

const state = {
    isCollapse: false,
    userTypeList: [],
    systemTime: "",
    systemDate: "",
    systemMonth: "",
    systemYear: "",
    systemList: []
};

const mutations = {
    [types.INDEX_COLLAPSE](state, status) {
        state.isCollapse = status;
    },
    [types.USER_TYPE_LIST](state, status) {
        state.userTypeList = [...status];
    },
    [types.SYSTEM_TIME](state, status) {
        state.systemTime = status.sysdate2;
    },
    [types.SYSTEM_DATE](state, status) {
        state.systemDate = status.sysdate;
    },
    [types.SYSTEM_MONTH](state, status) {
        state.systemMonth = status.sysdate3;
    },
    [types.SYSTEM_YEAR](state, status) {
        state.systemYear = status.sysdate4;
    },
    [types.SYSTEM_LIST](state, status) {
        state.systemList = [...status];
    }
};

const getters = {};

const actions = {
    getCodeList({ commit, dispatch }) {
        api.getCodelistByKind({
            code_kind: "unit_type;sys_code"
        }).then(res => {
            if (res) {
                commit("USER_TYPE_LIST", res.bus_json[0].codelists);
                commit("SYSTEM_LIST", res.bus_json[1].codelists);
                dispatch("getSysDate");
            }
        });
    },
    getSysDate({ commit, dispatch }) {
        api.getSysDate().then(res => {
            if (res) {
                commit("SYSTEM_TIME", res.bus_json);
                commit("SYSTEM_DATE", res.bus_json);
                commit("SYSTEM_MONTH", res.bus_json);
                commit("SYSTEM_YEAR", res.bus_json);
            }
        });
    }
};

export default {
    state,
    actions,
    getters,
    mutations
};
